package example.strategy.symmetry;


import com.scop.desensitize.encry.rreversible.symmetry.AbstractSymmetryEncry;
import com.scop.desensitize.exception.strategy.DecodeException;
import com.scop.desensitize.exception.strategy.EncodeException;
import com.scop.desensitize.strategy.rreversible.symmetry.AesStrategy;
import org.apache.log4j.Logger;

import java.security.NoSuchAlgorithmException;

/**
 * @desc Aes策略类的使用示例
 */
public class AesStrategyDemo {

	public static Logger log = Logger.getLogger(AesStrategyDemo.class);

	public static void main(String[] args) throws EncodeException, DecodeException {
		String data = "scop";

		/**
		 * @desc  默认密码加密
		 */
		defaultEncry(data);

		/**
		 * @desc  自定义密码加密
		 */
		//customEncry(data);
	}

	/**
	 * @desc 自定义偏移量，密码
	 */
	public static void customEncry(String data) throws EncodeException, DecodeException {
		AbstractSymmetryEncry aes= AesStrategy.getInstance();

		aes.setIV_PARAMETER("12332112");
		//密码必须是16位
		aes.setPassword("1234567812312378");

		String encodeStr = (String)aes.encode(data);
		String decodeStr = (String)aes.decode(encodeStr);

		log.debug("自定义密码加密--->默认数据：" + data);
		log.debug("自定义密码加密--->加密之后：" + encodeStr);
		log.debug("自定义密码加密--->解密之后：" + decodeStr);
	}

	/**
	 * @desc 默认执行密码执行
	 * @throws NoSuchAlgorithmException
	 */
	public static void defaultEncry(String data) throws EncodeException, DecodeException {
		AbstractSymmetryEncry aes=AesStrategy.getInstance();
		String encodeStr = (String)aes.encode(data);
		String decodeStr = (String)aes.decode(encodeStr);

		log.debug("默认密码加密--->默认数据：" + data);
		log.debug("默认密码加密--->加密数据：" + encodeStr);
		log.debug("默认密码加密--->解密数据：" + decodeStr);
	}
}
